/**
 * 遍历链表节点时将每个节点存储起来，使用Set，如果Set中存在则返回该节点
 * @param {ListNode} head
 * @return {ListNode}
 */
const detectCycle = head => {
  let set = new Set()
  while (head) {
    if (set.has(head)) {
      return head
    }
    set.add(head)
    head = head.next
  }
  return null
}